package com.mydemo.design_pattern.action_type.observer_pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * <p></p >
 *
 * @author liming1
 * @version $Id: Subject, v1.0 2019-09-23 14:40 liming1 Exp $
 */
public class Subject {

    public int state;

    public List<Observer> observers = new ArrayList<>();


    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void addObserver(Observer observer){
        observers.add(observer);
    }

    public void notifyAllObservers(){
        for (Observer observer : observers) {
            observer.update();
        }
    }
}
